package com.bysj.yqsht.web.controller;


import com.bysj.yqsht.bean.Subject;
import com.bysj.yqsht.bean.extend.SubjectExtend;
import com.bysj.yqsht.service.ISubjectService;
import com.bysj.yqsht.utils.Message;
import com.bysj.yqsht.utils.MessageUtil;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/subject")
@Api(description = "科目管理接口")
public class SubjectController {

    @Autowired
    private ISubjectService subjectService;

    @GetMapping("/findAll")
    public Message findAll(){
        List<Subject> Subject = subjectService.findAll();
        return MessageUtil.success(Subject);
    }
    @GetMapping("findpage")
    public Message findpage(@RequestParam(defaultValue = "1") int pageNum, @RequestParam(defaultValue = "10") int limit){
        List<Subject> subjects = subjectService.findpage(pageNum,limit);
        return MessageUtil.success(subjects);
    }

    @PostMapping("saveOrUpdate")
    public Message saverOrUpdate(Subject subject){
        subjectService.saveOrUpdate(subject);
        return MessageUtil.success("添加或修改成功");
    }
    @GetMapping("deleteById")
    public Message deleteById (long id){
        subjectService.deleteById(id);
        return MessageUtil.success("删除成功");
    }

}
